#!/bin/bash

# this export is requiered for i3 handle this script with its bindsym
export PATH=$HOME/.scripts/usb_mount:$PATH

if [ "$1" = "mount" ]
then
	choose=$(lsblk -l | grep part | grep -v \/ | awk {'print $1, $4'} | dmenu -p "device to mount")
	choose=$(echo $choose | awk {'print $1'})

	echo $(gpg -d Documents/oth/pass/systempass.gpg 2> /dev/null) | 
		\sudo -s mount -o gid=users,fmask=113,dmask=002 /dev/$choose /mnt/usb 2>/tmp/usb_mount_error

	msg=$(echo "$choose mounted in /mnt/usb")
else
	choose=$(lsblk -l | grep part | grep /mnt | awk {'print $1, $4'} | dmenu -p "device to umount")
	choose=$(echo $choose | awk {'print $1'})
	echo $(gpg -d Documents/oth/pass/systempass.gpg 2> /dev/null) | 
		\sudo -s umount /dev/$choose 2>/tmp/usb_mount_error

	msg=$(echo "$choose umounted")
fi

mount_status=$(< /tmp/usb_mount_error)
if [ -z $mount_status ]
then
	notify-send "$msg"
else
	notify-send "error: $mount_status"
fi
